package com.test.controller;

import com.test.bean.Product;
import com.test.bean.Result;
import com.test.bean.Uesr;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping
public class LoginController {
    @CrossOrigin(origins = "http://localhost:5173")
    @PostMapping("login")
    public Result<Uesr> login(@RequestBody Uesr uesr){
        System.out.println(uesr);
        Result result = new Result();
        result.setT(uesr);
        result.setSuccess(true);
        return result;
    }

    @GetMapping("products")
    public List<Product> getAllProducts(@RequestParam("token") String token,@RequestParam("name") String name) {
        System.out.println("接收到参数：" +token + ":  " + name);
        List<Product> products = new ArrayList<>();
        products.add(new Product("Product 1", "2024-11-01", 199.99, 0.8));
        products.add(new Product("Product 2", "2024-11-15", 299.99, 0.7));
        products.add(new Product("Product 3", "2024-11-15", 299.99, 0.7));
        // 更多商品
        return products;
    }

    @GetMapping("products/{id}")
    public Product getAllProducts(@PathVariable("id") Integer id) {
        System.out.println("接收到参数：" +id );
        // 更多商品
        return new Product("wdasfsadaf 1", "2024-11-01", 199.99, 0.8);
    }
}
